<?php

include_once ('bn_path.php');

class bn_lang
{
    private $conf;
    private $dir;
    private $gf;
    protected static $instance;

    function __construct()
    {
        $this->conf = new bn_config;
        $this->dir = new bn_directory;
        $this->gf=new bn_genralfunc;
    }

    public static function getInstance()
    {
        if (!isset(self::$instance))
        {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function lang_list($args=array('name' => 'langddl','cssclass'=>'select'))
    {
        $ddl=new bn_dropdownlist;
        $this->gf->class_property($ddl,$args);
        $list=$this->dir->get_dirlist(basepath . '/lang/', 'dir');
        $cnt=count($list);
        for($i=0;$i<$cnt;$i++)
        {
            $list[$i]=str_replace(basepath . '/lang/','',$list[$i]);
        }
        echo $ddl->show($list);
    }

    public function load_lang($filename, $lang = '')
    {
        $sam = $lang;
        if ($lang == '')
            $lang = $this->conf->get_default_lang();
        $lang = basepath . '/lang/' . $lang . '/' . $filename . '.php';
        if (file_exists($lang))
            include_once ($lang);
        else
            return 0;
    }


    function __destruct()
    {
        unset($this->conf);
        unset($this->dir);
        unset($this->gf);
    }


}

?>